package tmp.LeftORight;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
	public static void main(String[] args) throws SQLException {
		Connection con=DAO.DbcpConnection.getConnection();
		con.setAutoCommit(false);
		Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
		ResultSet rs=st.executeQuery("select * from all_detail");
		int count=0;
		while (rs.next()) {
			System.out.println(count++);
			String imagepath=rs.getString("imagepath");
			String sourcename=rs.getString("sourcename");
			String left_img=getLeft_img(imagepath,sourcename);
			String middle_img=getMiddle_img(imagepath,sourcename);
			String right_img=getRight_img(imagepath,sourcename);
			rs.updateString("left_img", left_img);
			rs.updateString("middle_img", middle_img);
			rs.updateString("right_img",right_img);
			rs.updateRow();
		}
		con.commit();
	}

	private static String getRight_img(String imagepath, String sourcename) {
		if(imagepath==null){
			return null;
		}
		String [] tmp=imagepath.split("\\|");
		if(sourcename.equals("yougou")){
			if(tmp.length>3){
				return tmp[3];
			}else{
				return null;
			}
		}
		else if(sourcename.equals("okbuy")){
			if(tmp.length>5){
				return tmp[5];
			}
		}
		return null;
	}

	private static String getMiddle_img(String imagepath, String sourcename) {
		if(imagepath==null){
			return null;
		}
		String [] tmp=imagepath.split("\\|");
		if(sourcename.equals("yougou")){
			if(tmp.length>0){
				return tmp[0];
			}else{
				return null;
			}
		}
		
		return null;
	}

	private static String getLeft_img(String imagepath, String sourcename) {
		if(imagepath==null){
			return null;
		}
		String [] tmp=imagepath.split("\\|");
		if(sourcename.equals("yougou")){
			if(tmp.length>2){
				return tmp[1];
			}else{
				return null;
			}
		}
		else if(sourcename.equals("okbuy")){
			if(tmp.length>3){
				return tmp[3];
			}
		}
		return null;
	}
}
